package com.atguigu.exam.service.impl;

import com.atguigu.exam.common.Result;
import com.atguigu.exam.entity.Banner;
import com.atguigu.exam.entity.Notice;
import com.atguigu.exam.mapper.BannerMapper;
import com.atguigu.exam.service.BannerService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 轮播图服务实现类
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {

    @Override
    public Result<String> toggleBannerStatus(Long id, Boolean isActive) {
        try {
            Banner banner = new Banner();
            banner.setId(id);
            banner.setIsActive(isActive);
            banner.setUpdateTime(new Date());
            boolean success = this.updateById(banner);
            if (success) {
                String status = isActive ? "启用" : "禁用";
                return Result.success("轮播图" + status + "成功");
            } else {
                return Result.error("轮播图状态更新失败");
            }
        } catch (Exception e) {
            return Result.error("轮播图状态更新失败：" + e.getMessage());
        }
    }
}